<style>
    #inbox{
        height:calc(100vh - 0px);
        position: relative;
    }
    #inbox .layout-inbox{
        opacity: 0;
        height: calc(100% - 50px);
    }
</style>
<!--inbox-->
<link rel="stylesheet" href="/views/inbox/tmp.css">
<link rel="stylesheet" href="/src/component/date/datepicker.css">
<section id="inbox">
    <div class="breadcrumb">
        <span>Inbox</span>
        <i class="iconfont icon-gengxin"></i>
        <i class="iconfont icon-get-email hide"></i>
    </div>
    <div class="layout-inbox feat-grid">
        <!-- allowOverflow auto-attached by option: west__showOverflowOnHover = true -->
        <div class="ui-layout-west">

            <div class="site-count fx-col-c">
                <div class="col-sm-24">replied emails：<span id="Replied">0</span></div>
                <div class="col-sm-24">Unprocessed emails：<span id="pendingReply">0</span></div>
            </div>
            <!--站点/标题-->
            <div class="site-header" id="site-header">
                <div id="headerInfo" class="fx-row-b">
                    <span class="header-img hide"><img src="" alt=""></span>
                    <!--选择框组件-->
                    <div class="header-select" id="site_id">
                        <select name="site_id">
                            <option value="">事业部</option>
                        </select>
                    </div>
                    <h4 class="header-num">0</h4>
                </div>
            </div>
            <!--search-->
            <div class="site-search fx-row-s">
                <div class="search-b fx-row-s">
                    <i class="iconfont icon-sousuo"></i>
                    <input type="text" name="search" placeholder="Email、TicketID">
                    <label class="load hide">
                        <i class="load-list"></i>
                        <i class="load-list"></i>
                        <i class="load-list"></i>
                        <i class="load-list"></i>
                    </label>
                </div>
                <i data-name="iconFanhui" class="hide">Back</i>
            </div>
            <!--email-->
            <ul id="siteEmail" data-name="menuItem" class="site-email">
                <li id="search" data-name="menuList" class="box-list">
                    <div data-name="menuTitle" class="list-title fx-row-b">
                        <span>Search Result</span>
                        <span data-name="title-num">0</span>
                    </div>
                    <div data-name="menuContent" class="list-content">
                        <section data-name="com-check" class="com-check"></section>
                    </div>
                </li>
                <li id="twentyFour" data-name="menuList" class="box-list">
                    <div data-name="menuTitle" class="list-title fx-row-b">
                        <span>Over 24 hours</span>
                        <span data-name="title-num">0</span>
                    </div>
                    <div data-name="menuContent" class="list-content">
                        <section data-name="com-check" class="com-check"></section>
                    </div>
                </li>
                <li id="now" data-name="menuList" class="box-list">
                    <div data-name="menuTitle" class="list-title fx-row-b">
                        <span>Within 24 hours</span>
                        <span data-name="title-num">0</span>
                    </div>
                    <div data-name="menuContent" class="list-content">
                        <section data-name="com-check" class="com-check"></section>
                    </div>
                </li>
            </ul>

            <div class="site-mark active-mark">
                <div class="mark-title row">
                    <span>Notes Records</span>
                    <i class="active-arrow iconfont icon-shangla"></i>
                </div>

                <div class="mark-box">
                    <textarea id="markContent"></textarea>
                    <div class="row">
                        <div class="col-sm-12">
                            <label>Customer service：</label>
                        </div>
                        <div class="col-sm-10 col-sm-offset-1 tr">
                            <span id="remarker" class="label-text" title=""></span>
                        </div>
                        <!--<div class="col-sm-12 fx-row-e tr">
                            <label>备注颜色：</label>
                            <select name="" id="">
                                <option value="">红色</option>
                                <option value="">绿色</option>
                                <option value="">红色</option>
                                <option value="">红色</option>
                            </select>
                        </div>-->

                    </div>
                    <div class="row mt10">
                        <div class="col-sm-12">
                            <label>Connect to ERP：</label>
                        </div>

                    </div>
                    <div class="row mt10">
                        <div class="col-sm-17">
                            <input id="erpOrder" type="text" class="form-input" placeholder="Enter the associated order number">
                        </div>
                        <div class="col-sm-6 col-sm-offset-1 fx-row-e tr">
                            <button id="addMark" type="button" class="btn-a">Notes</button>
                        </div>
                    </div>
                    <ul class="mark-content">

                    </ul>
                </div>

            </div>

        </div>

        <!--右侧-->
        <div class="ui-layout-east">
            <section id="" class="com-tab">
                <div class="tab-header">
                    <div class="header-item">
                        <div data-name="a" class="item-list active">orders&nbsp;&nbsp;<span class="searchBtn" style="color:blue;text-decoration: underline;">(search)</span></div>
                        <div data-name="b" class="item-list">email history</div>
                        <div class="header-line" style="width:133px;"></div>
                    </div>
                </div>
                <div class="tab-content">
                    <div data-name="tab-content-a" class="content-list">
                        <div class="order-no">
                            <img src="/src/img/order-no.jpg" alt="">
                            <h5>No order data ! <a id="searchBtn" class="searchBtn" href="javascript:;">Search?</a></h5>
                        </div>
                        <ul class="order-box">
                            <!--订单数据-->
                        </ul>
                    </div>
                    <div data-name="tab-content-b" class="content-list hide">
                        <table class="ticket-table">
                            <thead>
                                <tr>
                                    <th>Status</th>
                                    <th>ticket-SN</th>
                                    <th>lastest replied time</th>
                                    <th>customer service</th>
                                    <th>repeatCount</th>
                                </tr>
                            </thead>
                            <tbody id="oldTicket" class="nth">

                            </tbody>
                        </table>
                    </div>
                </div>
            </section>

        </div>

        <!--中间-->
        <div class="ui-layout-center">
            <div class="mes-header fx-col-c">
                <div id="mes-header-box">
                    <div class="row">
                        <span class="col-sm-8 site"><label>site：</label><span data-name="headSite"></span></span>
                        <span class="col-sm-8 reply"><label>Response times：</label> <span data-name="headReply"></span> </span>
                        <span class="col-sm-8 status">
                            <label>Status：</label>
                            <!--<span data-name="headStatus"></span>-->
                            <select class="hide" name="headStatus" style="border-radius: 4px;">
                                <option value="opened">Opened</option>
                                <option value="in_progress">Inprogress</option>
                            </select>
                        </span>
                    </div>
                    <div class="row">
                        <span class="col-sm-8 email"><label>User Mail：</label><span data-name="headEmail"></span></span>
                        <span class="col-sm-8 ticket"><label>Ticket-SN：</label><span data-name="headTicket"></span></span>
                        <span class="col-sm-8 outAuthor"><label>Customer service：</label> <span data-name="headAuthor"></span></span>
                    </div>
                </div>
                <i class="iconfont icon-xiangyou fold fold-z"></i>
                <i class="iconfont icon-xiangyou fold2"></i>
            </div>
            <section class="mes-child-box">
                <div class="child-north">
                    <div id="mesContent" class="mes-content">
                        <!--会话详情填充-->
                        <div class="mes-emmm">
                            <img src="/src/img/emmm.jpg" alt="">
                            <!--<h5 class="mt10">暂没有相关会话</h5>-->
                        </div>
                    </div>
                </div>
                <div class="child-center">
                    <div class="mes-send">
                        <!--<div class="send-title">
                            <p id="toggleAllPanes">45456</p>
                            <button id="btnReset">button</button>
                        </div>-->
                        <div id="editor-container"></div>
                    </div>
                </div>
            </section>

            <div class="mes-footer fx-row-b">
                <button type="button" id="send" class="btn-c c-pos">
                    <i class="send-animate"><span class="send-main"></span></i>
                    <span class="send-text">Send(Ctrl + Enter)</span>
                </button>
                <div>
                    <!--<button id="selTemplate" class="btn-d">选择模板</button>-->
                    <button id="staff" class="btn-a ml10">Assign(Alt + a)</button>
                    <button id="trash" class="btn-b ml10 hide" disabled="disabled">Delete(Alt + q)</button>
                </div>
            </div>
        </div>

    </div>
</section>

<!--template start-->
<!--header Site-->
<script id="inbox-site-list" type="text/html">
    <select name="site_id">
        {{each data as v i}}
        <option value="{{v.id}}">{{v.department_name}}</option>
        {{/each}}
    </select>
</script>

<!--email-list <input type="checkbox" value="{{v.ticket_id}}">-->
<!--menu-->
<script id="inbox-site-email" type="text/html">
    {{each list as v i}}
    <div data-accountId="{{v.account_id}}" data-email="{{v.distribution_email}}" class="content-list fx-col-c">
        <div class="list-email">
            <label>
                <i data-name="checkStyle" class="check-box hide"></i>
                <input type="checkbox" value="{{v.ticket_id}}">
            </label>
            <span class="email-text">{{v.distribution_email}}</span>
        </div>
        <div class="list-text">{{v.subject}}</div>
    </div>
    {{/each}}
</script>
<!--email-list-title <span>{{$imports.hoursNum}}</span>-->
<script id="inbox-site-email-title" type="text/html">
    {{total}}
</script>

<!--会话头部-->
<script type="text/html" id="inbox-talk-head">
    <div class="row">
        <span class="col-sm-8 email"><label>site：</label><span>{{site_name}}</span></span>
        <span class="col-sm-8 reply"><label>Response times：</label>{{reply_count}}</span>
        <span class="col-sm-8 outAuthor"><label>Status：</label>{{sys_flag}}</span>
    </div>
    <div class="row">
        <span class="col-sm-8 email"><label>User Mail：</label><span>{{receiver_email}}</span></span>
        <span class="col-sm-8 ticket"><label>Ticket-SN：</label><span>{{ticket_sn}}</span></span>
        <span class="col-sm-8 outAuthor"><label>Customer service：</label>{{nickname}}</span>
    </div>
</script>

<!--会话模板-->
<script type="text/html" id="inbox-talk">
    {{each list as v i}}
        <div class="content-list clearfix {{v.is_user == 1 ? 'client' : 'user'}}">
            <div class="content-head {{isHistory ? 'content-head-history' : ''}}">
                <i class="head-a"></i>
                <p>{{v.from_name}}</p>
            </div>
            <div class="content-detail">
                <div class="detail-header row">
                    <div class="col-sm-12">{{subject}}</div>
                    <div class="col-sm-12 tr">Sending Time: {{ v.create_time }}</div>
                </div>
                <div class="detail-text">
                    {{if v.text_html}}
                        {{@v.text_html}}
                    {{else}}
                        {{v.text_plain}}
                    {{/if}}
                </div>
                {{set tempFile = v.attachments}}
                <div class="detail-down">
                    {{each tempFile as childContent c}}
                        <a href="{{$imports.linkFilter(childContent)}}" target="_blank">下载{{c+1}}</a>
                    {{/each}}
                </div>
            </div>
        </div>
    {{/each}}
</script>

<!--erp订单列表模板-->
<script type="text/html" id="inbox-erp">
    {{each data as v i}}
    <li data-name="menuList" class="box-list">
        <!--基本订单信息-->
        <div data-name="menuTitle" class="box-title">
            <div class="row">
                <div class="col-sm-16"><label>order number：</label><span class="label-text order"><a href="{{v.erp_order_href}}" target="_blank" id="orderNo">{{v.order_sn}}</a></span></div>
                <div class="col-sm-8"><label>status：</label><span class="label-text">{{v.order_status}}</span></div>
            </div>
            <div class="row">
                <div class="col-sm-16"><label>site：</label><span class="label-text">{{v.site}}</span></div>
                <div class="col-sm-8"><label>Quantity：</label><span class="label-text">{{v.GoodList.length}}</span></div>
            </div>
        </div>
        <div class="box-content" data-name="menuContent">
            <!--详细订单信息-->
            <div class="list-message">
                <div class="row">
                    <div class="col-sm-16"><label>Order time：</label><span class="label-text" title="">{{v.AddTime}}</span></div>
                    <div class="col-sm-8"><label>disputed or not：</label><span class="label-text" title="">{{v.IsDisputed}}</span></div>
                </div>
                <div class="row">
                    <div class="col-sm-16"><label>pay time：</label><span class="label-text" title="">{{v.PayTime}}</span></div>
                    <div class="col-sm-8"><label>refunded or not：</label><span class="label-text">{{v.RefundType}}</span></div>
                </div>
                <div class="row">
                    <div class="col-sm-16"><label>paid：</label><span class="label-text" title="">{{v.final_price}} ; {{v.FinalPrice}}</span></div>
                    <div class="col-sm-8"><label>Freight fee：</label><span class="label-text">{{v.ShippingPrice}}</span></div>
                </div>
                <div class="row">
                    <div class="col-sm-16"><label>activity：</label><span class="label-text" title="">{{v.CActivePrice}}</span></div>
                    <div class="col-sm-8"><label>discount：</label><span class="label-text">{{v.DiscountPrice}}</span></div>
                </div>
                <div class="row">
                    <div class="col-sm-16"><label>payment method：</label><span class="label-text" title="">{{v.PayType}}</span></div>
                    <div class="col-sm-8"><label>currency：</label><span class="label-text" id="currencyName">{{v.Currency.Name}}</span></div>
                </div>
                <div class="row">
                    <div class="col-sm-16"><label>shipping method：</label><span class="label-text">{{v.ShippingType}}</span></div>
                </div>
                <div class="row">
                    <div class="col-sm-16"><label>Transaction number：</label><span class="label-text">{{v.Tx}}</span></div>
                </div>
            </div>
            <!--订单商品列表-->
            <ul class="list-content">
                {{each v.GoodList as val index}}
                    <li class="content-list">
                        <div class="list-text">
                            <div class="text-line row">
                                <div class="col-sm-16"><label>SPU：</label><span class="skuId">{{val.SPU}}</span></div>
                                <div class="col-sm-8"><i class="line-status">{{val.Status}}</i></div>
                            </div>

                            <div class="text-line row">
                                <div class="col-sm-12"><label>Sku：</label><span>{{val.SkuId}}</span></div>
                                <label class="col-sm-12 tr">
                                    {{val.SKU}}
                                </label>
                            </div>
                            <div class="text-line row">
                                <div class="col-sm-24"><label>price：</label><span class="productPrice">{{val.Price}}</span></div>
                            </div>
                            <div class="text-line row">
                                <div class="col-sm-24"><label>Tracking NO：</label><span>{{val.ExpressNo || 'null'}}</span></div>
                            </div>
                        </div>
                        <!--<div class="list-img" style="background-image:url({{ 'http://pms-hk.aopcdn.com/orgin/' + val.ThumbnailsUrl + '?x-oss-process=image/resize,m_lfit,h_60,w_60' }})"></div>-->
                        <div class="list-img">
                            <img src="{{ 'https://pms-hk.aopcdn.com/orgin/' + val.ThumbnailsUrl + '?x-oss-process=image/resize,m_lfit,h_60,w_60' }}" alt="">
                        </div>
                    </li>
                {{/each}}
            </ul>
        </div>
    </li>
    {{/each}}
</script>


<!--selectTmp-->
<script id="inbox-select-tmp" type="text/html">
    <div class="staff-box">
        <h4 class="box-title">
            请选择模板:
        </h4>
        <i class="box-close">&times;</i>
        <section class="com-select-floor">
            <div class="sel-item">
                <input class="sel-head" type="text" value="" readonly UNSELECTABLE="on" placeholder="请选择"/>
                <input type="hidden" value="">
                <i class="sel-icon"></i>
            </div>
            <div class="sel-box"></div>
        </section>
    </div>
</script>

<!--生成优惠券弹出的模板dom-->
<script id="outCouponTmp" type="text/html">
    <section class="feat-grid">
        <form id="form" class="box-content">
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5 must">Order Number：</label></div>
                <div class="col-sm-12 form-content"><input type="text" name="orderNo" class="form-input"></div>
                <div class="col-sm-6"><span class="label-description">
                    Currency：<span id="currencySymbol"></span></span>
                </div>
            </div>
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5">Products：</label></div>
                <div class="col-sm-12 form-content"><input type="text" name="skuList" class="form-input"></div>
                <div class="col-sm-6"><span class="label-description">Amount：<span id="checkedPriceTotal">0</span></span></div>
            </div>
            <div class="form-item row">
                <div class="col-sm-offset-6 col-sm-15 form-content">
                    <section id="select-sku" data-name="com-check" class="com-check">
                    </section>
                </div>
            </div>
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5 must">Coupon Amount：</label></div>
                <div class="col-sm-12 form-content"><input type="text" name="amount" class="form-input"></div>
            </div>
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5 must">Currency：</label></div>
                <div class="col-sm-12 form-content">
                    <select name="currencyCode" class="select-a">
                        <option value=""></option>
                    </select>
                </div>
            </div>
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5 must">Active Dates：</label></div>
                <div class="col-sm-12 form-content">
                    <div class="c-datepicker-date-editor  J-datepicker-range-day">
                        <i class="c-datepicker-range__icon kxiconfont icon-clock"></i>
                        <input placeholder="Start Date" name="startTime" class="c-datepicker-data-input only-date" value="">
                        <span class="c-datepicker-range-separator">-</span>
                        <input placeholder="End date" name="endTime" class="c-datepicker-data-input only-date" value="">
                    </div>
                </div>
            </div>
            <div class="form-item row">
                <div class="col-sm-6"><label class="form-title-5 must">Reason：</label></div>
                <div class="col-sm-12 form-content">
                    <!--select floor-->
                    <section class="com-select-floor" style="z-index: 1000">
                        <div class="sel-item">
                            <input class="sel-head" type="text" value="" readonly UNSELECTABLE="on" placeholder="please select"/>
                            <input name="reasonId" type="hidden" value="">
                            <i class="sel-icon"></i>
                        </div>
                        <div class="sel-box"></div>
                    </section>
                    <div class="other-reason"><input type="text" name="reason" class="form-input" placeholder="Other Reason(please note)"></div>
                </div>
            </div>
        </form>
    </section>
</script>

<!--备注列表-->
<script id="inbox-mark-list" type="text/html">
    {{each data as v i}}
        <li class="content-list">
            <div class="list-text row">
                <div class="col-sm-17">{{v.note_text}}</div>
                <div class="col-sm-6 col-sm-offset-1">{{v.action == 'zhipai' ? 'Assign a note' : ''}}</div>
            </div>
            <div class="list-remark row">
                <div class="col-sm-20"><span>Customer service：</span><span class="label-text" title="">{{v.note_admin_name}}</span></div>
                <div class="col-sm-4 tr"><i data-id="{{v.note_md5}}" class="iconfont icon-shanchu"></i></div>
            </div>
        </li>
    {{/each}}
</script>

<!--ticket历史列表-->
<script id="inbox-oldTicket-list" type="text/html">
    {{each data as v i}}
        <tr class="ticket-head-tr">
            <td>{{v.sys_flag}}</td>
            <td class="ticket-td" data-id="{{v.ticket_id}}">{{v.ticket_sn}}</td>
            <td>{{v.last_reply_time}}</td>
            <td>{{v.name}}</td>
            <td>{{v.repeatCount}}</td>
        </tr>
        <tr class="ticket-detail-tr hide">
            <td class="ticket-detail mes-content" colspan="5"></td>
        </tr>
    {{/each}}
</script>

<script id="inbox-search-content" type="text/html">
    <section>
        <p style="margin-left: 23px;margin-bottom:10px;">Please input the email address or order number </p>
        <form id="form-search" class="box-content" novalidate="novalidate">
            <div class="form-item row">
                <div class="col-sm-24"><label class="form-title-5">email：</label></div>
                <div class="col-sm-16 form-content"><input type="text" name="email" class="form-input"></div>
            </div>
            <div class="form-item row">
                <div class="col-sm-24"><label class="form-title-5">Order Number：</label></div>
                <div class="col-sm-16 form-content"><input type="text" name="orderNo" class="form-input"></div>
            </div>
        </form>
    </section>
</script>

<!--checked列表-->
<div id="tmpCheckList" class="hide">
    <label data-name="price" data-price="">
        <i data-name="checkStyle" class="check-box"></i>
        <input type="checkbox" value="">
        <div class="img-box">
            <img src="" alt="">
        </div>
        <div class="img-sku"></div>
    </label>
</div>

<script src="/src/lib/jquery-ui-latest.js"></script>
<script src="/src/lib/jquery.layout-1.3.0.rc30.80.js"></script>

<script src="/src/js/inbox/coupon.js"></script>
<script src="/src/js/inbox/outher.js"></script>
<script src="/src/component/quill/quill.min.js"></script>
<script src="/src/component/quill/quill-img.js"></script>
<script>

    $.extend(window.p,{
        //当前站点Id
        account_id:com.getCookie("account_id") ? com.getCookie("account_id") : para.user.account_ids[0],
        business_id:com.getCookie("business_id") ? com.getCookie("business_id") : '',

        pageNum:20,
        quill:null,
        myLayout:null,
        selectStaff:null,
        selectTmp:null,
        layerObj:null,
        now:{
            page:1,
            reqSwitch:true,
            comCheck:null,
            ticketTmpArr:null,
            orderTmpArr:null,
            error:0
        },
        twentyFour:{
            page:1,
            reqSwitch:true,
            comCheck:null,
            ticketTmpArr:null,
            orderTmpArr:null,
            error:0
        },
        search:{
            page:1,
            reqSwitch:true,
            comCheck:null,
        },
        coupon:{
            orderId:-1
        },
        reasonOuther:null,
        src:[
            //'/src/lib/debug.js'
            "/src/component/date/moment.min.js",
            "/src/component/date/datepicker.all.js",
            "/src/lib/jquery.validate.min.js"

            //拉伸框架需要在dom前加载
            //'/src/lib/jquery-ui-latest.js',
            //'/src/lib/jquery.layout-1.3.0.rc30.80.js',
        ],
        reqTicketObj:null,
        erpRequestObj:null,
        oldReqTicketListObj:null,
        markListObj:null,
        //缓存数量
        cacheNum:5,
        //缓存时间
        cacheExpire:1,
        //人员权限状态存储
        statusArr:[],
        skuArr:[],
        currency:'',
        isMenu:true,
        abort:null,
    });

$(function(){

    template.defaults.imports.linkFilter = linkFilter;

    initEvent();

    function initEvent(){

        //菜单Menu
        $(".site-email").comMenu();
        $(".order-box").comMenu();

        //初始化菜单选择组件(checked方法可返回所选择的邮件ticket数组)
        p.now.comCheck = $("#now").comCheck();
        p.twentyFour.comCheck = $("#twentyFour").comCheck();
        p.search.comCheck = $("#search").comCheck();

        reqStatus();

        //菜单滚动异步处理
        $("#siteEmail").find(".list-content").on("scroll",function(){
            var top = $(this).scrollTop();
            var scrollHeight = $(this)[0].scrollHeight;
            var docHeight = $(this).height();
            var name = '';
            //参数3: 滑动至尾部仅剩3条时触发异步请求
            if(top+docHeight >= (scrollHeight-70*3)){
                name = $(this).closest("[data-name='menuList']").prop('id');
                menuRequest({
                    hoursName:name,
                    init:false,
                });
            }
        });

        //更新缓存
        $(".icon-gengxin").on('click',function(){
            clearCache();
            menuBox();
        });

        //选择人员指派
        $("#staff").on('click',function(){
            p.selectStaff = com.layerInsert(para.staffList,function(){
                $("[data-name='staffListObj']").comSelect({
                    init:true,
                    search:true,
                    callback:function(val,text){
                        para.staffId = val;
                    }
                });

                var mObj = $("#markContentNotes");
                    mObj.removeClass('hide');

                //指派确定按钮
                $(".staff-button").on("click",function(){
                    var w = $(".site-email").children('.active').prop('id');
                    var checkList = [];
                    p.urlPara ? checkList.push(p.urlPara) : checkList = [p.ticket_id];//p[w].comCheck.checked();
                    if(checkList.length < 1){
                        $.comMessage({
                            type:'prompt',
                            text:'Please tick the mail!',
                        });
                        return;
                    }

                    app.ajax({
                        type:'post',
                        url:app.api('/api/mail/owner/' + para.token),
                        data:{
                            ticket_id:checkList.join(','),
                            cs_admin_id:para.staffId,
                            admin_id:para.user.admin_id,
                        },
                        success:function(res){
                            if(res.code == 0){
                                p.urlPara && (location.href = '/'+para.path+'#inbox');
                                $.comMessage({
                                    type:'success',
                                    text:'Successful assignment!',
                                });
                                addMark('b');
                                //重新请求数据
                                reqReply();
                                pendingReply();
                                getBusinessCount(p.business_id);

                                //删除缓存数据
                                delCacheData(p.handlerMenu,'ticket',p.ticket_id);
                                delCacheData(p.handlerMenu,'order',p.ticket_id);
                                menuRequest({
                                    hoursName:w,
                                    init:true,
                                    tap:true
                                });
                            }else{
                                $.comMessage({
                                    type:'warning',
                                    text:res.msg,
                                });
                            }
                            p.selectStaff.close();
                        }
                    });
                })
            });
        });

        //垃圾箱
        $("#trash").on('click',function(){
            var w = $(".site-email").children('.active').prop('id');
            var checkList = [];
                p.urlPara ? checkList.push(p.urlPara) : checkList = [p.ticket_id];//p[w].comCheck.checked();
            if(checkList.length <= 0){
                $.comMessage({
                    type:'prompt',
                    text:'Please tick the mail!',
                });
                return;
            }

            $.alert({
                message:'Will you delete from Trash?',
                okText:'confirm',
                cancelText:'cancel',
                okHandler:function(){
                    app.ajax({
                        type:'post',
                        url:app.api('/api/ticket/trashBin/' + para.token),
                        data:{
                            ticket_id:checkList.join(','),
                            admin_id:para.user.admin_id,
                        },
                        success:function(res){
                            if(res.code == 0){
                                p.urlPara && (location.href = '/'+para.path+'#inbox');
                                $.comMessage({
                                    type:'success',
                                    text:'success！',
                                });

                                //重新请求数据
                                reqReply();
                                pendingReply();
                                getBusinessCount(p.business_id);

                                //删除缓存数据
                                delCacheData(p.handlerMenu,'ticket',p.ticket_id);
                                delCacheData(p.handlerMenu,'order',p.ticket_id);
                                menuRequest({
                                    hoursName:w,
                                    init:true,
                                    tap:true
                                });
                            }else{
                                $.comMessage({
                                    type:'warning',
                                    text:res.message,
                                });
                            }
                        }
                    });
                }
            })


        });

        //发送请求回复
        $("#send").on('click',function(){
            var that = $(this);
            var content = p.quill.container.firstChild.innerHTML;
            var len = p.quill.getLength();
            var w = $(".site-email").children('.active').prop('id');

            if(!p.ticket_sn){
                $.comMessage({
                    type:'prompt',
                    text:'Ticket does not exist!',
                });
                return;
            }
            if(len>1){
                that.addClass('active-animate');
                that.prop("disabled",true);
                insertMessage();
                //return;
                app.ajax({
                    type:'post',
                    url:app.api('/api/mail/reply/' + para.token),
                    data:{
                        in_reply_to:p.in_reply_to,
                        receiver_email:p.receiver_email,
                        references_str:p.references_str,
                        reply_p_message_id:p.reply_p_message_id,
                        subject:p.subject,
                        ticket_sn:p.ticket_sn,
                        text_html:content,
                        admin_id:para.user.admin_id,
                        from_account_id:p.account_id
                    },
                    success:function(res){
                        if(res.code == 0){
                            p.urlPara && (location.href = '/'+para.path+'#inbox');
                            $.comMessage({
                                type:'success',
                                text:'success！',
                            });

                            //重新请求数据
                            reqReply();
                            pendingReply();
                            getBusinessCount(p.business_id);

                            //删除缓存数据
                            delCacheData(p.handlerMenu,'ticket',p.ticket_id);
                            delCacheData(p.handlerMenu,'order',p.ticket_id);
                            menuRequest({
                                hoursName:w,
                                init:true,
                                tap:true
                            });

                            p.quill.container.firstChild.innerHTML = "";
                        }else{
                            $.comMessage({
                                type:'warning',
                                text:res.message,
                            });
                        }
                    },
                    error:function(xml,status){
                        if(status == 'timeout'){
                            $.comMessage({
                                type:'warning',
                                text:'网络请求超时！'
                            })
                        }else{
                            $.comMessage({
                                type:'warning',
                                text:'网络请求错误！'
                            })
                        }
                    },
                    complete:function(){
                        that.removeClass('active-animate');
                        that.prop("disabled",false);
                    }
                });

            }else{
                $.comMessage({
                    type:'prompt',
                    text:'Please fill in the reply text！',
                });
            }
        });

        //发送
        /*document.onkeydown = function(e) {
            if (13 == e.keyCode && e.ctrlKey) {
                var focus = document.activeElement.className;
                if(focus == 'ql-editor ql-blank'){
                    $("#send").trigger('click');
                }
            }
        };*/
        $(document).on({
            'keydown':function(e) {
                var str = document.activeElement.className;
                var reg = new RegExp('ql-editor');
                var isTrue = reg.test(str) ? true : false;

                //发送
                if (13 == e.keyCode && e.ctrlKey && isTrue) {
                     $("#send").trigger('click');
                }
                //指派
                if(65 == e.keyCode && e.altKey && isTrue){
                    if($(".staff-box").length >=1){return}
                    $("#staff").trigger('click');
                }
                //垃圾箱
                if(81 == e.keyCode && e.altKey){
                    if($(".com-prompt").length >=1){return}
                    $("#trash").trigger('click');
                }

                //优惠券
                if(67 == e.keyCode && e.altKey){
                    if($("#form").length >=1){return}
                    $(".ql-coupon").trigger('click');
                }
                //补差价
                if(76 == e.keyCode && e.altKey){
                    if($(".com-prompt").length >=1){return}
                    $(".ql-spread").trigger('click');
                }
                //光标进入notes
                if(e.keyCode == 70 && e.altKey && e.ctrlKey){
                    $("#markContent").focus();
                }
                //note备注
                if(e.keyCode == 78 && e.altKey && e.ctrlKey){
                    $("#addMark").trigger('click');
                }
                //滚动
                if(e.keyCode == 40 && e.altKey && e.ctrlKey){
                    var mesObj = $('#mesContent');
                    //mesObj.scrollTop(mesObj.scrollTop() + 150)
                    mesObj.animate({scrollTop: mesObj.scrollTop() + 200},150)
                }
                if(e.keyCode == 38 && e.altKey && e.ctrlKey){
                    var mesObj = $('#mesContent');
                    mesObj.animate({scrollTop: mesObj.scrollTop() - 200},150)
                }
                //切换
                if(e.keyCode == 84 && e.altKey && e.ctrlKey){
                    var headerObj = $('.header-item');
                    var name = headerObj.children('.active').attr('data-name');
                    name == 'a' ? headerObj.find("[data-name='b']").trigger('click') : headerObj.find("[data-name='a']").trigger('click');

                }
                //搜索
                if(e.keyCode == 13){
                    var activeName = document.activeElement.name;
                    if(activeName == 'search'){
                        $(".icon-sousuo").trigger('click');
                    }
                }
            }
        })
        //指派


        //邮件对话
        $("[data-name='menuItem']").on('click','.content-list',function(e){
            if(e.target.nodeName == 'I' || e.target.nodeName == 'INPUT'){
                return
            }
            var that = $(this);
            var val = that.find('input').val();
            var email = that.attr('data-email');
            var accountId = that.attr('data-accountId');

            p.handlerMenu = that.closest('.box-list').attr('id');
            p.ticket_id = val;
            //p.coupon.orderUserMail = email;
            p.account_id = accountId;

            if(e.ctrlKey){
                window.open('/'+para.path+'#inbox/' + p.ticket_id,'_blank')
            }
            //邮件详情
            reqTicket(val,that);
            //erp
            erpRequest();
            //ticket历史
            oldReqTicketList(email);
            //备注列表
            markList(val);
        });

        //历史邮件对话
        $(".ticket-table").on('click','.ticket-td',function(){
            var id = $(this).attr('data-id');
            oldReqTicket(id,$(this).closest('tr'));
        });

        //选择站点邮件数量logo变更事件
        $("#site-header").on('change',"select[name='site_id']",function(){
            var checked = $(this).find("option:checked");

            p.business_id = checked.val();
            com.setCookie("business_id",p.business_id,24);

            //清除缓存数据
            clearCache();

            p.urlPara ? (location.href = '/'+para.path+'#inbox') : location.reload();
            //重新请求菜单数据
            //menuBox();
        });

        //搜索结果
        $(".icon-sousuo").on('click',function(){
            searchResult()
        });

        $(".searchBtn").on('click',function(){
            var dom = $("#inbox-search-content").html();
            p.layerSearchObj = new ComLayer({
                title:'search order information',
                dom:dom,
                width:"500px",
                okHandler:function(btnObj){
                    //var isTrue = $("#form-search").valid();
                    //if(isTrue){
                        var email = $("input[name='email']").val();
                        var orderNo = $("input[name='orderNo']").val();
                        erpRequest(email,orderNo,btnObj)
                    //}
                },
                callback:function(){
                    /*$("#form-search").validate({
                        rules: {
                            email:{required:true,},
                        },
                        messages: {
                            email:{required:'Please input the email address!',},
                        },
                    });*/
                },
            })
        });

        $("[data-name='iconFanhui']").on('click',function(){
            var searchObj = $("#search");
            $(this).addClass('hide');
            $("[name='search']").val('');
            searchObj.siblings(".box-list").show();
            searchObj.find("[data-name='com-check']").html("");
            searchObj.hide().removeClass('active');
        });

        //切换状态
        $("[name='headStatus']").on('change',function(){
            var val = $(this).val();
            app.ajax({
                type:'post',
                url:app.api('/api/ticket/status/update'),
                data:JSON.stringify({
                   ticketId:p.ticket_id,
                   status:val
                }),
                success:function(res){
                    if(res.code == 0){
                        $.comMessage({
                            type:'success',
                            text:res.message
                        })
                        //删除缓存数据
                        delCacheData(p.handlerMenu,'ticket',p.ticket_id);
                        delCacheData(p.handlerMenu,'order',p.ticket_id);
                        menuRequest({
                            hoursName:p.handlerMenu,
                            init:true,
                            tap:true
                        });
                    }
                }
            })
        });

        //tab切换
        $(".com-tab").find(".tab-header").find('.item-list').on('click',function(){
            var that = $(this);
            var text = that.attr("data-name");
            var tabObj = $(".tab-content");
            tabObj.children('.content-list').addClass('hide');
            tabObj.find("[data-name='tab-content-"+text+"']").removeClass('hide');

            that.addClass('active').siblings('.item-list').removeClass('active');
            //动态计算line的位置及其宽度
            var left = that.position().left;
            var width = that.css('width');
            $(".header-line").css({
                'left':left + 'px',
                'width':width
            });
        })

        //备注相关
        $(".mark-title").on('click',function(){
            $(".site-mark").toggleClass('active-mark')
        });
        $("#remarker").html(para.user.admin_nickname);
        //添加
        $("#addMark").on('click',function(){
            addMark('a');
        });
        //删除
        $(".mark-content").on('click','.icon-shanchu',function(){
            var md5 = $(this).attr('data-id');
            deleteMark(md5);
        });

        //初始请求菜单数据
        if(p.urlPara){
            //如果有参数(from processed)
            p.ticket_id = p.urlPara;
            reqTicket(p.urlPara);
            $(".icon-get-email,.site-email,.site-search,.site-count").hide();
            $(".site-mark").addClass('active-detail').find('.active-arrow').remove();
            //$("[name='site_id']").prop('disabled',true)
        }else{
            reqReply();
            pendingReply();
            getBusiness();
        }

        if(para.user.operation.trashbin){
            $("#trash").removeClass('hide').prop('disabled',false)
        }else{
            $("#trash").remove();
        }

    }

    //备注列表
    function markList(val){
        p.markListObj && p.markListObj.abort();
        p.markListObj = app.ajax({
            type:'post',
            url:app.api('/api/note/list'),
            data:JSON.stringify({
                ticketId:val
            }),
            success:function(res){
                if(res.code == 0){
                    var tmp = template('inbox-mark-list',res);
                    $(".mark-content").html(tmp);
                }else{
                    $.comMessage({
                        type:'prompt',
                        text:res.message,
                    })
                }
            }
        });
    }

    //新增备注
    function addMark(type){
        var content = "";

        if(type == 'a'){
            content = $("#markContent").val();
        }/*else{
            content = $("#markContentNotes").val();
        }*/

        if(!p.ticket_id){
            $.comMessage({
                type:'prompt',
                text:'Please select ticket!',
            });
            return;
        }
        if(type=='a' && !content){
            $.comMessage({
                type:'prompt',
                text:'Please enter the note content!',
            });
            return;
        }
        app.ajax({
            type:'post',
            url:app.api('/api/note/save'),
            data:JSON.stringify({
                ticketId:p.ticket_id,
                type:"No",
                content:content ? content : 'Assign',
                orderNo:$("#erpOrder").val(),
                action:type == 'b' ? 'zhipai' : 'default'
            }),
            success:function(res){
                if(res.code == 0){
                    clearMark();
                    markList(p.ticket_id);
                    $.comMessage({
                        type:'prompt',
                        text:res.message,
                    })
                }else{
                    $.comMessage({
                        type:'prompt',
                        text:res.message,
                    })
                }
            }
        });
    }

    function deleteMark(m){
        app.ajax({
            type:'post',
            url:app.api('/api/note/delete'),
            data:JSON.stringify({
                ticketId:p.ticket_id,
                md5:m
            }),
            success:function(res){
                if(res.code == 0){
                    markList(p.ticket_id);
                    $.comMessage({
                        type:'prompt',
                        text:res.message,
                    })
                }else{
                    $.comMessage({
                        type:'prompt',
                        text:res.message,
                    })
                }
            }
        });
    }

    //清除备注信息
    function clearMark(){
        $("#markContent").val('');
        $("#erpOrder").val('')
    }

    //已回复
    function reqReply(){
        app.ajax({
            type:'post',
            url:app.api('/api/mail/count'),
            success:function(res){
                if(res.code == 0){
                    $("#Replied").html(res.data.count);
                }else{
                    $.comMessage({
                        type:'prompt',
                        text:res.message,
                    })
                }
            }
        });
    }
    //待回复
    function pendingReply(){
        app.ajax({
            type:'post',
            url:app.api('/api/ticket/count'),
            success:function(res){
                if(res.code == 0){
                    $("#pendingReply").html(res.data.count);
                }else{
                    $.comMessage({
                        type:'prompt',
                        text:res.message,
                    })
                }
            }
        });
    }

    //默认获取站点或者更新总站点数量
    function getBusiness(paraData){
        app.ajax({
            type:'post',
            url:app.api('/api/business/list'),
            success:function(res){
                if(res.code == 0){
                    var listTmp = template('inbox-site-list', res);
                    $("#site_id").html(listTmp);
                    //cookie如果有默认站点
                    var isTrue = false;
                    if(!p.business_id){
                        p.business_id = res.data[0].id;
                    }

                    //设置：遍历cookie中的默认存储事业部
                    $("select[name='site_id']").find('option').each(function(index,item){
                        var itemObj = $(item);
                        if(p.business_id == itemObj.attr('value')){
                            itemObj.prop('selected','selected');
                            isTrue = true;
                            return false;
                        }
                    });

                    //如果找不到匹配的事业部则默认重置第一个
                    if(!isTrue){
                        $("select[name='site_id']").find('option').eq(0).prop('selected','selected');
                        p.business_id = res.data[0].id;
                    }

                    com.setCookie("business_id",p.business_id,24);
                    getBusinessCount(p.business_id);
                    menuBox();
                }else{
                    $.comMessage({
                        type:'prompt',
                        text:res.message
                    })
                }
            }
        });
    }
    //获取事业部数量
    function getBusinessCount(businessUnitId){
        app.ajax({
            type:'post',
            url:app.api('/api/business/count'),
            data:JSON.stringify({
                businessUnitId:businessUnitId
            }),
            success:function(res){
                if(res.code == 0){
                    $(".header-num").html(res.data.count)
                }else{
                    $.comMessage({
                        type:'prompt',
                        text:res.message
                    })
                }
            }
        });
    }

    function menuBox(){
        $(".box-list").removeClass('active').find('.list-content').hide();
        //24小时
        menuRequest({
            hoursName:'twentyFour',
            init:true
        });

        //now
        menuRequest({
            hoursName:'now',
            init:true
        });
    }
    //请求菜单数据
    function menuRequest(op){
        if(op.hoursName == 'search'){
            return;
            //searchResult()
        }else if(p[op.hoursName].reqSwitch){
            p[op.hoursName].reqSwitch = false;
            //var startTime = 0;
            //var endTime = 0;
            var type = '';
            var name = op.hoursName;
            switch(op.hoursName){
                case 'twentyFour':
                    //startTime = 24;
                    //endTime = 0;
                    type = 1;
                    break;
                case 'now':
                    //startTime = 0;
                    //endTime = 24;
                    type = 0;
                    break;
            }

            if(op.init){
                p[name].page=1;
            }else{
                p[name].page++;
            }

            app.ajax({
                type:'post',
                url:app.api('/api/ticket/list'),
                data:JSON.stringify({
                    type:type,
                    page:p[name].page,
                    limit:p.pageNum,
                    businessUnitId:p.business_id
                }),
                beforeSend:function(){},
                success:function(res){
                    if(res.code == 0){
                        //renderHoursList(res,$("#"+ name),name,init)
                        if(!res.data.list || res.data.list.length<1){
                            op.tap && nextData();
                            return
                        }
                        var insertBox = $("#"+ name);
                        //对应时间数量
                        var tmpTitle = template('inbox-site-email-title', res.data);
                        //列表
                        var tmpContent = template('inbox-site-email', res.data);

                        insertBox.find("[data-name='title-num']").html(tmpTitle);
                        if(op.init){
                            insertBox.find("[data-name='com-check']").html(tmpContent)
                        }else{
                            insertBox.find("[data-name='com-check']").append(tmpContent);
                        }
                        op.tap && nextData();

                        //缓存数据
                        updateCached(name);
                    }else{
                        //var hoursObj = $("#"+ name);
                        //hoursObj.find('[data-name="title-num"]').html(0);
                        //hoursObj.find("[data-name='com-check']").html('');
                    }
                },
                complete:function(){
                    //状态判断还不完全。
                    p[name].reqSwitch = true;
                }
            });
        }
    }


    //邮件对话
    function reqTicket(val,that){

        p.reqTicketObj && p.reqTicketObj.abort();
        //本地如果有缓存则取出缓存数据
        var cacheData = getCacheData(p.handlerMenu,'ticket',val);
        if(cacheData){
            reqTicketRender(cacheData,that);
            return;
        }

        var loadObj = null;
        p.reqTicketObj = app.ajax({
            type:'get',
            url:app.api('/api/ticket/detail/' + para.token + "/" + val),
            beforeSend:function(){
                loadObj = $.load({
                    insert:$(".mes-content"),
                    background:"rgba(255,255,255,.7)"
                });
            },
            success:function(res){
                if(res.code == 0){
                    reqTicketRender(res,that)
                }
            },
            complete:function(){
                loadObj.close()
            }
        });
    }
    //邮件对话渲染
    function reqTicketRender(res,that){
        var dom = template('inbox-talk',res.data);
        //var domHead = template('inbox-talk-head',res.data);
        //$("#mes-header-box").html(domHead);
        renderHead(res);
        $(".mes-content").html(dom);

        that && that.addClass('active-info').siblings('.content-list').removeClass('active-info');
        that && that.closest(".box-list").siblings(".box-list").find('.content-list').removeClass('active-info');

        p.in_reply_to = res.data.in_reply_to;
        p.receiver_email = res.data.receiver_email;
        p.references_str = res.data.references_str;
        p.reply_p_message_id = res.data.reply_p_message_id;
        p.subject = res.data.subject;
        p.ticket_sn = res.data.ticket_sn;
        p.siteId = res.data.site_id;
        p.account_id = res.data.account_id;

        //如果详情进来
        if(p.urlPara){
            erpRequest();
            //ticket历史
            oldReqTicketList(res.data.receiver_email);
            markList(p.urlPara);
        }
    }
    function linkFilter(str){
        var a = str.replace(/^(\/storage)/,'http://storage.orderplus.com/');
        return a;
    }

    //渲染头部
    function renderHead(res){
        var data = res.data;
        $("[data-name='headSite']").html(data.site_name + " ("+data.erp_site_name+") " || "");
        $("[data-name='headReply']").html(data.reply_count || "");
        $("[data-name='headEmail']").html(data.receiver_email || "");
        $("[data-name='headTicket']").html(data.ticket_sn || "");
        $("[data-name='headAuthor']").html(data.nickname || "");

        var selectObj = $("[name='headStatus']");
        var handlerVal = data.sys_flag;

        selectObj.find('option').each(function(index,item){
            var that = $(item);
            if(that.attr('value') == handlerVal){
                selectObj.val(handlerVal);
                return false;
            }
        });
        selectObj.removeClass('hide');
        if(p.statusArr.length){
            selectObj.prop('disabled',false);
        }else{
            selectObj.prop('disabled',true);
        }
    }



    //请求状态
    function reqStatus(){
        app.ajax({
            type:'get',
            async:false,
            url:app.api("/api/ticket/status/list"),
            success:function(res){
                if(res.code == 0 && res.data.length>1){
                    p.statusArr = res.data;
                }
            },
        })
    }

    //erp请求
    function erpRequest(email,orderNo,btnObj){

        var loadObj = null;

        p.erpRequestObj && p.erpRequestObj.abort();

        //本地如果有缓存则取出缓存数据
        var cacheData = getCacheData(p.handlerMenu,'order',p.ticket_id);
        if(cacheData && cacheData.data.length>=1){
            erpRequestRender(cacheData);
            return;
        }
        p.erpRequestObj = app.ajax({
            type:'post',
            url:app.api('/api/order/list'),
            data:JSON.stringify({
                ticketId:p.ticket_id,
                mail:email || "",
                orderNo:orderNo || ""
            }),
            beforeSend:function(){
                $(".order-no").addClass('hide');
                $(".order-box").html('');
                loadObj = $.load({
                    insert:$("[data-name='tab-content-a']"),
                    style:'style2'
                });
                //判断是否手动查询
                if(btnObj){btnObj.addClass('active-animate')}
            },
            success:function(res){
                if(res.code == 0){
                    erpRequestRender(res);
                    //判断是否手动查询
                    if(btnObj){p.layerSearchObj.close()}
                }else if(res.code == 2){
                    $.comMessage({
                        type:'warning',
                        text:res.message
                    })
                }
            },
            error:function(xmlObj,status){
                if(status == 'timeout'){
                    $.comMessage({
                        type:'warning',
                        text:'api请求超时！'
                    })
                }else{
                    /*$.comMessage({
                        type:'warning',
                        text:'api请求错误！'
                    })*/
                }
                $(".order-box").html("");
                $(".order-no").removeClass('hide');
            },
            complete:function(){
                loadObj.close();
                //判断是否手动查询
                if(btnObj){btnObj.removeClass('active-animate')}
            }
        })
    }
    function erpRequestRender(res){
        $(".order-no").addClass('hide');
        var tmp = template('inbox-erp', res);
        $(".order-box").html(tmp);
        if(!res.data.length){
            $(".order-box").html("");
            $(".order-no").removeClass('hide');
        }
    }


    //历史的ticket请求
    function oldReqTicket(val,that){

        //that.closest('table').find('.ticket-detail-tr').addClass('hide');

        that.next('.ticket-detail-tr').siblings('.ticket-detail-tr').addClass('hide');
        that.next('.ticket-detail-tr').toggleClass('hide');
        var str = that.next('.ticket-detail-tr').children('td').html();
        if(str.length>=1){return;}
        var loadObj = null;
        app.ajax({
            type:'get',
            url:app.api('/api/ticket/detail/' + para.token + "/" + val),
            beforeSend:function(){
                loadObj = $.load({
                    insert:that.next('.ticket-detail-tr').children('td'),
                    style:'style2',
                    text:'loading'
                })
            },
            success:function(res){
                if(res.code == 0){
                    res.data.isHistory = true;
                    var dom = template('inbox-talk',res.data);
                    that.next('.ticket-detail-tr').children('td').html(dom);
                    //that.next('.ticket-detail-tr').removeClass('hide');
                }
            },
            complete:function(){
                loadObj.close()
            }
        });
    }

    function oldReqTicketList(email){
        p.oldReqTicketListObj && p.oldReqTicketListObj.abort();
        p.oldReqTicketListObj = app.ajax({
            type:'post',
            data:JSON.stringify({
                mail:email,
                accountId:p.account_id
            }),
            url:app.api('/api/ticket/history'),
            success:function(res){
                if(res.code == 0){
                    var tmp = template('inbox-oldTicket-list',res);
                    $("#oldTicket").html(tmp);
                }
            },
            complete:function(){

            }
        });
    }


    app.dynamicLoadJs(p.src,"inbox",function(){

        p.myLayout = $('.layout-inbox').layout({
            livePaneResizing:true,
            spacing_open:5,
            //togglerAlign_open: "right"
            //west__minSize:350
            //west__size:350
            center__minWidth:0,
            west__showOverflowOnHover:true,
            stateManagement__enabled:true, // automatic cookie load & save enabled by default
            showDebugMessages:true, // log and/or display messages from debugging & testing code
            west: {
                closable:false,
                minSize:300,
                size:350,
            },
            east:{
                minSize:1,
                size:350,
                slideTrigger_open:"mouseover",
                spacing_closed:0
            },
            center__paneSelector:".ui-layout-center",
            east__paneSelector:	".ui-layout-east",
            west__paneSelector:	".ui-layout-west",
            contentSelector:".mes-child-box",
            center__childOptions:{
                north__paneSelector:".child-north",
                center__paneSelector:".child-center",
                resizerTip:'调节',
                livePaneResizing:true,
                spacing_open:5,
                closable:false,
                north__minSize:300,
                north__size:400,
                //north__minHeight:150,

                center__minHeight:40,
                center__size:300
            }
        });

        //动态生成按钮后操作
        function initQuill(){
            var couponObj = $('.ql-coupon');
            var spreadObj = $(".ql-spread");
            couponObj.addClass('iconfont icon-youhuiquan');
            spreadObj.addClass('iconfont icon-lianjie');
            //优惠券生成
            couponObj.on('click',function(){
                isUseCoupon();
            }).prop('title','Create Discount Code');
            //差价链接
            spreadObj.on('click',function(){
                spread();
            }).prop('title','Difference Price Link');

            //差价链接
            function spread(){
                app.ajax({
                    type:'post',
                    url:app.api('/api/link/diff'),
                    data:JSON.stringify({
                        siteId:p.siteId
                    }),
                    success:function(res){
                        if(res.code == 0 && res.data.url){
                            $.alert({
                                message:res.data.url,
                                detail:'Please copy',
                                singleButton:true,
                                okText:'Ok',
                            })
                        }else{
                            $.comMessage({  //可选(warning/success/prompt)
                                type:'prompt',
                                text:res.message,
                            });
                        }
                    }
                })
            }

            //是否可以弹框
            function isUseCoupon(){
                var d = JSON.stringify({
                    siteId:p.siteId || 0
                });
                p.abort && p.abort.abort();
                p.abort = app.ajax({
                    type:'post',
                    url:app.api('/api/coupon/checkSite'),
                    data:d,
                    success:function(res){
                        if(res.code == 0){
                            if(!res.data.result){
                                $.comMessage({  //可选(warning/success/prompt)
                                    type:'prompt',
                                    text:'This site does not have a docking code generation function!',
                                });
                                return;
                            }
                            //优惠码
                            var dom = $("#outCouponTmp").html();
                            p.layerObj = new ComLayer({
                                title:'Create Discount Code',
                                dom:dom,
                                okHandler:function(btnObj){
                                    var isDate = ($("[name='startTime']").val() && $("[name='endTime']").val()) ? true : false;
                                    var reasonId = $("[name='reasonId']").val();
                                    if(!isDate){
                                        $.comMessage({  //可选(warning/success/prompt)
                                            type:'prompt',
                                            text:'Please fill in the date range！',
                                        });
                                        return;
                                    }
                                    if(!reasonId){
                                        $.comMessage({  //可选(warning/success/prompt)
                                            type:'prompt',
                                            text:'Please choose the reason！',
                                        });
                                        return;
                                    }

                                    var reason = $("input[name='reasonId']").val().split(',');
                                    if(reason.length <=1){
                                        $.comMessage({  //可选(warning/success/prompt)
                                            type:'prompt',
                                            text:'Please choose secondary reasons!',
                                        });
                                        return;
                                    }

                                    /*//是否选择其他原因
                                    $("[name='reasonId']").val() == 10  ? (p.reasonOuther = true) : (p.reasonOuther = false);

                                    //添加规则
                                    $("[name='reason']").rules(
                                        "add",
                                        {
                                            required:p.reasonOuther,
                                            messages:{required:'Please fill in other reasons!'}
                                        }
                                    );*/

                                    var isTrue = $("#form").valid();
                                    if(isTrue){
                                        btnObj.addClass('active-animate').prop('disabled',true);
                                        requestCoupon(btnObj);
                                    }
                                },
                                callback:layerInit,
                            })
                        }else{
                            $.comMessage({  //可选(warning/success/prompt)
                                type:'prompt',
                                text:res.message,
                            })
                        }
                    }
                })
            }
        }

        const quillConfig = [
            [{ header: [1, 2,3,4, false] }],
            ['bold', 'italic', 'underline'],
            ['image', /*'code-block'*/],
            ['coupon'],
            ['spread']
        ];


        p.quill = new Quill('#editor-container', {
            modules: {
                toolbar:quillConfig,
                imageDrop: true,
            },
            placeholder: 'Compose an epic...',
            theme: 'snow'  // or 'bubble'
        });
        initQuill();


        $('.layout-inbox').css('opacity','1');
        $(".fold").on('click',function(){
            var isHidden = $(".ui-layout-east").is(":hidden");
            isHidden ? $(this).removeClass('fold-z') : $(this).addClass('fold-z');
        })
        p.myLayout.bindButton('.fold', 'toggle', 'east');
        p.myLayout.bindButton('.fold2','open', 'west');
        $("#btnReset").click(function(){
            //myLayout.loadState(stateResetSettings, true)
        });
    });


    //获取ticket条目
    function getMenuDataId(){
        var arr = [];
        $("#twentyFour").find('.content-list').each(function(index,item){
            var obj = {
                accountId:$(item).attr('data-accountid'),
                email:$(item).attr('data-email'),
                id:$(item).find(":checkbox").val()
            };
            arr.push(obj);
        });
        //p['twentyFour'].ticketArr = arr;
        return arr;
    }


    //调用更新缓存数据并覆盖本地
    function updateCached(name){
        p[name].ticketTmpArr = getMenuDataId();
        p[name].orderTmpArr = getMenuDataId();
        reqCacheTicket(name,p[name].ticketTmpArr[0]);
        reqCacheOrder(name,p[name].orderTmpArr[0]);
    }

    //是否拿取数据
    function isData(name,type){
        var data = com.getData(name+"_"+type,'arr');
        if(!data){
            return 0;
        }
        if(data.length){
            return data.length;
        }
    }

    //返回数据ticket数据
    function getCacheData(name,type,id){
        var result = null;
        if(isData(name,type)>0){
            var data = com.getData(name+"_"+type,'arr');
            $.each(data,function(index,item){
                if(item.id == id){
                    result = item.source;
                    return false;
                }
            })
        }
        if(result){
            return result;
        }else{
            return false;
        }
    }

    //设置数据
    function setCacheData(name,type,source,id){
        var arr = [];
        var num = isData(name,type);
        //如果当前数据包和
        if(num > 0){
            var d = com.getData(name+"_"+type,'arr');
            if(d && d.length >=1){
                arr = d;
            }
        }

        var obj = {
            id:id,
            source:source,
        };
        arr.push(obj);
        if(type == 'ticket'){
            //p[name].ticketArr = arr;
            com.setData(name+"_"+type,{arr:arr},p.cacheExpire);
        }else{
            //p[name].orderArr = arr;
            com.setData(name+"_"+type,{arr:arr},p.cacheExpire);
        }
        return arr;
    }

    //删除对应的ticket数据
    function delCacheData(name,type,ticketId){
        var arr = com.getData(name+"_"+type,'arr');
        if(arr && arr.length){
            $.each(arr,function(index,item){
                if(item.id == ticketId){
                    arr.splice(index,1);
                    return false;
                }
            });
            com.setData(name+"_"+type,{arr:arr},p.cacheExpire);
        }
    }

    //默认加载页面调用清除
    function clearCache(){
        localStorage.removeItem('twentyFour_order');
        localStorage.removeItem('twentyFour_ticket');
        localStorage.removeItem('now_order');
        localStorage.removeItem('now_ticket');
    }

    //并发请求ticket
    function reqCacheTicket(name,ticketObj){
        var ticketId = ticketObj && ticketObj.id;
        if(!ticketId){return}
        //连续错误3次则中断递归请求
        if(p[name].error > 3){return;}

        var isTrue = false;
        var type = 'ticket';
        var num = isData(name,type);
        var ticketData = com.getData(name+"_"+type,'arr');

        //满足五条则返回
        if(num>=p.cacheNum){return}

        //0条数据直接请求;其余对比后无重复则发起请求
        if(num>0 && num<p.cacheNum){
            $.each(ticketData,function(index,item){
                if(item.id == ticketId){
                    isTrue = true;
                    return false;
                }
            });
        }

        if(isTrue){
            p[name].ticketTmpArr.shift();
            reqCacheTicket(name,p[name].ticketTmpArr[0])
        }else{
            app.ajax({
                type:'get',
                //async:false,
                url:app.api('/api/ticket/detail/' + para.token + "/" + ticketId),
                success:function(res){
                    if(res.code == 0 && res.data.list.length>0){
                        setCacheData(name,type,res,ticketId);
                        p[name].error = 0;
                    }else{
                        p[name].error++;
                    }
                },
                error:function(){
                    p[name].error++;
                },
                complete:function(){
                    p[name].ticketTmpArr.shift();
                    reqCacheTicket(name,p[name].ticketTmpArr[0]);
                }
            });
        }
    }

    //并发请求订单
    function reqCacheOrder(name,ticketObj){
        if(!ticketObj){return}
        var email = ticketObj.email;
        var accountId = ticketObj.accountId;
        var ticketId = ticketObj.id;
        if(!email || !accountId ||!ticketId){return}
        //连续错误3次则中断递归请求
        if(p[name].error > 3){return;}

        var isTrue = false;
        var type = 'order';
        var num = isData(name,type);
        var orderData = com.getData(name+"_"+type,'arr');

        //满足五条则返回
        if(num>=p.cacheNum){return}

        //0条数据直接请求;其余对比后无重复则发起请求
        if(num>0 && num<p.cacheNum){
            $.each(orderData,function(index,item){
                if(item.id == ticketId){
                    isTrue = true;
                    return false;
                }
            });
        }

        if(isTrue){
            p[name].orderTmpArr.shift();
            reqCacheOrder(name,p[name].orderTmpArr[0])
        }else{
            app.ajax({
                type:'post',
                //async:false,
                url:app.api('/api/order/list'),
                data:JSON.stringify({
                    ticketId:ticketId,
                }),
                success:function(res){
                    if(res.code == 0 && res.data.length>0){
                        setCacheData(name,'order',res,ticketId)
                        p[name].error = 0;
                    }else{
                        p[name].error++;
                    }
                },
                error:function(){
                    p[name].error++;
                },
                complete:function(){
                    p[name].orderTmpArr.shift();
                    reqCacheOrder(name,p[name].orderTmpArr[0])
                }
            })
        }
    }


});



</script>



<!--
    let stateResetSettings = {
        north__size:		"auto"
        ,	north__initClosed:	false
        ,	north__initHidden:	false
        ,	south__size:		"auto"
        ,	south__initClosed:	false
        ,	south__initHidden:	false
        ,	west__size:			200
        ,	west__initClosed:	false
        ,	west__initHidden:	false
        ,	east__size:			300
        ,	east__initClosed:	false
        ,	east__initHidden:	false
    };

-->